package com.dms.modules.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dms.common.api.ApiResponse;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

public abstract class BaseUserController<T, S extends IService<T>> {
    
    protected abstract S getService();
    
    @GetMapping("/list")
    public ApiResponse<Page<T>> list(T entity) {
        Page<T> page = new Page<>(1, 10);
        return ApiResponse.success(getService().page(page, new QueryWrapper<>(entity)));
    }
    
    @GetMapping("/{id}")
    public ApiResponse<T> getInfo(@PathVariable Long id) {
        return ApiResponse.success(getService().getById(id));
    }
    
    @PostMapping
    public ApiResponse<Boolean> add(@RequestBody T entity) {
        return ApiResponse.success(getService().save(entity));
    }
    
    @PutMapping
    public ApiResponse<Boolean> edit(@RequestBody T entity) {
        return ApiResponse.success(getService().updateById(entity));
    }
    
    @DeleteMapping("/{ids}")
    public ApiResponse<Boolean> remove(@PathVariable Long[] ids) {
        return ApiResponse.success(getService().removeByIds(Arrays.asList(ids)));
    }
} 